﻿
using System.Diagnostics;
using Net11_Task;

Demo();
DemoTask();

void Demo()
{
    char ac = '中';
    Console.WriteLine(ac);

    A a = new A();
    Console.WriteLine(InterA.A());
    Console.WriteLine(a.B());
    Console.WriteLine(A.C());
}

void DemoTask()
{
    Task tA = Task.Run(() =>
    {
        Task.Delay(1000);
        Console.WriteLine("A...");
    });
    List<Task> list = new List<Task>();
    list.Add(tA);
    var tB = new Task(() => Console.WriteLine("B..."));
    var tC = new Task(() => Console.WriteLine("C..."));
    list.Add(tB);
    list.Add(tC);
    tA.ContinueWith(a =>
    {
        Console.WriteLine("...");
        tB.Start();
        tC.Start();
    });
    Task.WaitAll(list.ToArray());
    Console.WriteLine("end.");
}

int threadNum = 27;
int[][] typeArray = new int[100][];
for (var i = 0; i < 100; i++)
{
    var innerArray = new int[i];
    for (var j = 0; j < i; j++)
    {
        innerArray[j] = j;
    }
    typeArray[i] = innerArray;
}

ParallelOptions parallelOptions = new ParallelOptions
{
    MaxDegreeOfParallelism = threadNum
};
Parallel.ForEach(typeArray, parallelOptions, currentArray =>
{
    Debug.WriteLine($"CurrentThreadId:{Thread.CurrentThread.ManagedThreadId},执行{string.Join(',', currentArray)}");
    foreach (var num in currentArray)
    {
        Thread.Sleep(num);
    }
});

var a = await Task.Run(() => "hello");